package com.market.quote.common;

import com.market.quote.interfaces.rest.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author duweibin
 * @date 2024/4/22
 * @description com.market.quote.common
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResultVO<?> handleException(Exception ex) {
        log.error("服务内部错误",ex);
       return ResultVO.of(CommonStatus.INTERNAL_SERVER_ERROR,null);
    }

    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public ResultVO<?> handleCustomException(Exception ex) {
        log.error("业务内部错误",ex);
        return ResultVO.of(CommonStatus.INTERNAL_SERVER_ERROR.getCode(),ex.getMessage(),null);
    }

    @ExceptionHandler(MethodArgumentNotValidException.class)
    @ResponseBody
    public ResultVO<?> handleArgumentException(MethodArgumentNotValidException ex) {
        log.error("参数错误",ex);
        return ResultVO.of(CommonStatus.ARGUMENT_ERROR.getCode(), ex.getMessage(),null);
    }


}
